package framework.transport.codec;

import framework.enums.CompressTypeEnum;
import framework.enums.SerializationTypeEnum;
import framework.enums.XMessageTypeEnum;
import framework.extension.ExtensionLoader;
import lombok.Data;

import java.io.Serializable;

@Data
public class XMessage extends XProtocolV1 implements Serializable {

    /**
     * rpc message type
     */
    private byte messageType;
    /**
     * serialization type
     */
    private byte codec = SerializationTypeEnum.HESSIAN.getCode();
    /**
     * compress type
     */
    private byte compress = CompressTypeEnum.GZIP.getCode();
    /**
     * request id
     */
    private String requestId;
    /**
     * request data
     */
    private Object data;

    public static XMessage getRequest(XRequest xRequest) {

        XMessage xMessage = new XMessage();
        xMessage.setMessageType(XMessageTypeEnum.REQUEST.getCode());
        xMessage.setRequestId(xRequest.getRequestId());
        xMessage.setData(xRequest);
        return xMessage;
    }
}
